
function debounce(func: Function, time: number, immediate: boolean=false) {
  let timer: number | null = null;
  console.log('防抖');
  return function() {
    if (timer) {
      window.clearInterval(timer);
    }
    if (immediate) {
      if (!timer) {
        func.apply(func, ...arguments);
      }
      timer = window.setTimeout(() => timer = null, time);
    } else {
      timer = window.setTimeout(() => func.apply(func, ...arguments), time);
    }
  }
}

export { debounce }